using System;
using System.Collections.Generic;
using System.Text;
using HundredMilesSoftware.UltraID3Lib;
using System.Reflection;
using System.Net;

namespace GotLyrics
{
    /// <summary>
    /// 
    /// </summary>
    public class LyricGrabberContext
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Mp3File"/> class.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public LyricGrabberContext(string filename)
        {
            _filename = filename;
            LoadMp3File(filename);
        }

        private Tags _tags;
        /// <summary>
        /// Gets the tags.
        /// </summary>
        /// <value>The tags.</value>
        public Tags Tags
        {
            get { return _tags; }
        }

        private string _filename;
        /// <summary>
        /// Gets the filename.
        /// </summary>
        /// <value>The filename.</value>
        public string Filename
        {
            get { return _filename; }
        }

        /*private int _state;
        /// <summary>
        /// Gets or sets the state.
        /// </summary>
        /// <value>The state.</value>
        /// <remarks>Use this to keep track of your scrape process</remarks>
        public int State
        {
            get { return _state; }
            set { _state = value; }
        }

        /// <summary>
        /// Resets this instance. (<see cref="State"/> and <see cref="WebClient"/>)
        /// </summary>
        public void Reset()
        {
            State = 0;
            _wc = null;
        }*/

        private List<LyricResult> _lyrics = new List<LyricResult>();
        /// <summary>
        /// Gets the lyrics found so far.
        /// </summary>
        /// <value>The lyrics.</value>
        public List<LyricResult> Lyrics
        {
            get { return _lyrics; }
        }

        private void LoadMp3File(string filename)
        {
            if (string.IsNullOrEmpty(filename))
                throw (new ArgumentNullException("filename"));


            UltraID3 id3 = new UltraID3();

            try
            {
                id3.Read(filename);
            }
            catch (Exception ex)
            {
                throw(new ApplicationException("Error occured while reading the contents of \"" + filename + "\"", ex));
            }

            _tags = new Tags(id3);
        }

        public void Write()
        {
            Tags.ID3.Write();
        }
    }
}
